//
//  PhotoCollectionView.m
//  时光电影项目
//
//  Created by 墨狂之逸才 on 15/7/23.
//  Copyright (c) 2015年 墨狂之逸才. All rights reserved.
//

#import "PhotoCollectionView.h"

@implementation PhotoCollectionView

- (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout
{
    self = [super initWithFrame:frame collectionViewLayout:layout];
    if (self) {
        
        //设置代理为自己
        self.dataSource = self;
        self.delegate = self;
        
        //是UIScrollView的子类，拥有其属性
        self.pagingEnabled = YES;
        //注册单元格
        [self registerClass:[PhotoCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
        
    }
    
    return self;
}




#pragma mark - set方法
- (void)setImageUrlArray:(NSArray *)imageUrlArray
{
    _imageUrlArray = imageUrlArray;
    
    //重新加载数据
    [self reloadData];
}



- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return _imageUrlArray.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    PhotoCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    
    //讲数据传递给cell，让他自己来定制内容,传递具体某一个值，当具体某个url传递过去，cell要重新显示数据，这里要调用cell的set 方法——- (void)setImageUrlStr:(NSString *)imageUrlStr
    cell.imageUrlStr = _imageUrlArray[indexPath.row];
    
    return cell;
    
    
}

- (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    //将cell取出来
    PhotoCollectionViewCell *photoCell = (PhotoCollectionViewCell *)cell;
    
    //设置放大倍数
    PhotoScrollView *scrollView = (PhotoScrollView *)[photoCell.contentView viewWithTag:100];
    
    
    scrollView.zoomScale = 1;
    
    
    
}



@end
